package adminDynamicFieldEntry

type Enum struct {
	Name  string
	Value string
}

func register(key, name, value string) Enum {
	one := Enum{
		Name:  name,
		Value: value,
	}
	enumMap = make(map[string][]Enum)
	enumMap[key] = append(enumMap[key], one)
	return one
}

var enumMap map[string][]Enum

func (v Enum) IsValid(key, value string) bool {
	if es, exi := enumMap[key]; exi {
		for _, e := range es {
			if value == e.Value {
				return true
			}
		}
	}
	return false
}

func Get(key string) []Enum {
	if es, exi := enumMap[key]; exi {
		return es
	}
	return nil
}

// 字段属性(主要用于字段基础判断)
var (
	Text       = register("field-attr", "文本", "text")
	SelectOne  = register("field-attr", "单选", "select-one")
	SelectMore = register("field-attr", "多选", "select-more")
	File       = register("field-attr", "文件", "file")
	DateOne    = register("field-attr", "单日期", "date-one")
	DateMore   = register("field-attr", "多日期", "date-more")
	Number     = register("field-attr", "数字", "number")

	WebInput    = register("field-web-type", "普通文本输入", "web-input")
	WebTextarea = register("field-web-type", "多行文本", "web-textarea")
	WebNumber   = register("field-web-type", "数字输入框", "web-number")
	WebRadio    = register("field-web-type", "单选框组", "web-radio")
	WebCheckbox = register("field-web-type", "复选框组", "web-checkbox")
	WebSelect   = register("field-web-type", "下拉框", "web-select")
	WebDate     = register("field-web-type", "日期", "web-date")
	WebUpload   = register("field-web-type", "上传按钮", "web-upload")
	WebHidden   = register("field-web-type", "隐藏域", "web-hidden")
	WebCustom   = register("field-web-type", "自定义片段", "web-custom")

	YYYY           = register("field-date-format", "2025", "yyyy")
	YYYYMM         = register("field-date-format", "2025-11", "yyyyMM")
	YYYYMMDD       = register("field-date-format", "2025-11-09", "yyyyMMdd")
	YYYYMMDDHH     = register("field-date-format", "2025-11-09 13", "yyyyMMdd HH")
	YYYYMMDDHHMM   = register("field-date-format", "2025-11-09 13:45", "yyyyMMdd HHmm")
	YYYYMMDDHHMMSS = register("field-date-format", "2025-11-09 13:45:30", "yyyyMMdd HHmmss")
	HHMMSS         = register("field-date-format", "13:45:30", "HHmmss")

	DsmUnsigned    = register("field-date-space-mark", "无符号[]", "unsigned")
	DsmCrossBar    = register("field-date-space-mark", "横杆[-]", "cross-bar")
	DsmUnderLine   = register("field-date-space-mark", "下划线[_]", "under-line")
	DsmColon       = register("field-date-space-mark", "冒号[:]", "colon")
	DsmDiagonalBar = register("field-date-space-mark", "斜杆[/]", "diagonal-bar")
	DsmCn          = register("field-date-space-mark", "斜杆[cn]", "cn")
)

// FieldBool 存储bool
type FieldBool string

const (
	FbYes FieldBool = "y" // 是
	FbNo  FieldBool = "n" // 是
)

func (v FieldBool) ToString() string {
	return string(v)
}
